package com.ruoyi.system.controller;


import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.system.domain.SysDataAsset;
import com.ruoyi.system.domain.SysDataLineage;
import com.ruoyi.system.service.ISysDataAssetService;
import com.ruoyi.system.service.ISysDataLineageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 血缘关系Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/lineage")
public class SysDataLineageController extends BaseController
{
    @Autowired
    private ISysDataLineageService sysDataLineageService;

    @Autowired
    private ISysDataAssetService sysDataAssetService;

    /**
     * 获取数据资产列表
     */
    @GetMapping("/assets")
    public TableDataInfo assets(SysDataAsset asset) {
        startPage();
        List<SysDataAsset> list = sysDataAssetService.selectSysDataAssetList(asset);
        return getDataTable(list);
    }

    /**
     * 查询血缘关系列表
     */
    //@PreAuthorize("@ss.hasPermi('system:lineage:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDataLineage sysDataLineage)
    {
        startPage();
        List<SysDataLineage> list = sysDataLineageService.selectSysDataLineageList(sysDataLineage);
        return getDataTable(list);
    }

    /**
     * 获取血缘图谱数据
     */
    @GetMapping("/graph")
    public AjaxResult getLineageGraph(@RequestParam Long assetId,
                                      @RequestParam(defaultValue = "2") int depth) {
        Map<String, Object> graphData = sysDataLineageService.getLineageGraph(assetId, depth);
        return AjaxResult.success(graphData);
    }

    /**
     * 获取血缘关系详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:lineage:query')")
    @GetMapping(value = "/{lineageId}")
    public AjaxResult getInfo(@PathVariable("lineageId") Long lineageId)
    {
        return AjaxResult.success(sysDataLineageService.selectSysDataLineageById(lineageId));
    }

    /**
     * 新增血缘关系
     */
    //@PreAuthorize("@ss.hasPermi('system:lineage:add')")
    @PostMapping
    public AjaxResult add(@RequestBody SysDataLineage sysDataLineage)
    {
        return toAjax(sysDataLineageService.insertSysDataLineage(sysDataLineage));
    }

    /**
     * 修改血缘关系
     */
    //@PreAuthorize("@ss.hasPermi('system:lineage:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody SysDataLineage sysDataLineage)
    {
        return toAjax(sysDataLineageService.updateSysDataLineage(sysDataLineage));
    }

    /**
     * 删除血缘关系
     */
    //@PreAuthorize("@ss.hasPermi('system:lineage:remove')")
    @DeleteMapping("/{lineageIds}")
    public AjaxResult remove(@PathVariable Long[] lineageIds)
    {
        return toAjax(sysDataLineageService.deleteSysDataLineageByIds(lineageIds));
    }
}
